package com.guang.listener.controller;

import com.guang.listener.demo5.entity.UserInfo;
import com.guang.listener.entity.MyEntity;
import com.guang.listener.event.MyEntityEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Title: ListenerController
 * @Author liguang
 * @Package com.guang.listener.controller
 * @Date 2024/11/15 13:30
 * @description:
 */
@RestController
public class ListenerController {

    @Resource
    private ApplicationContext applicationContext;

    @GetMapping(path = "demo1")
    public ResponseEntity<String> demo1() {
        applicationContext.publishEvent(new MyEntityEvent(new MyEntity("demo1", 1, "demo1")));
        return ResponseEntity.ok("demo1");
    }

    /**
     *
     * @return
     */
    @GetMapping(path = "demo2")
    public ResponseEntity<String> demo2() {
        applicationContext.publishEvent(new UserInfo(1L, "guang", "guang"));
        return ResponseEntity.ok("demo1");
    }

}
